

#include <stdio.h>
#include <stdlib.h>
#define OK 	1
#define ERR 0
typedef char ElemType;
typedef int  Status;

typedef struct Node
{
	ElemType data;
	struct Node *next;
}LinkList;

LinkList l;

/*创建单链表，头插法*/
void CreateListF(LinkList *L, ElemType *b, int n)
{
	LinkList *t;
	L = (LinkList*)malloc(sizeof(LinkList));
	L->next = NULL;
	for(int i = 0; i < n; i++){
		
		t =(LinkList*)malloc(sizeof(LinkList));
		t->data = b[i];
		t->next = L->next;
		L->next = t;
	}
}

void CreateListR(LinkList *L, ElemType *b, int n)
{
	LinkList *t ,*r;
	r = L;
	
	for(int i = 0; i < n; i++){
		
		t =(LinkList*)malloc(sizeof(LinkList));
		t->data = b[i];
		r->next = t;
		r = t;
	}
	r -> next = NULL;
}
Status ListInsert(LinkList *L, int index, ElemType d)
{
	LinkList *t, *e;
	int count = 0;
	e = L;
	t = (LinkList*)malloc(sizeof(LinkList));
	t->data = d;
	
	while(count < index - 1){
		e = e->next;
		count++;
	}
	t->next = e->next;
	e->next = t;
	return OK;
}

Status GetListItem(LinkList L, int index, ElemType *d)
{
	int count = 0;
	LinkList t = L;
	printf("%c\n",t.next->data);
//	while(!t && count < index){
//		t = t->next;	
//		count++;
//	}
//	if(t == NULL)
//		return ERR;
//	*d = t->data;
	return OK;
}

int main(void)
{
//	LinkList *l = (LinkList*)malloc(sizeof(LinkList));
	char buf[5] = "1234";
	ElemType val = 0;
//	CreateListF(l,buf,4);
	CreateListR(&l,buf,4);
	GetListItem(l,1,&val);
	printf("%c\n",val);
//	printf("%c\n",l.next->data);

	ListInsert(&l,2,'A');
//	printf("%c\n",l.next->next->next->next->next->data);
	

	return 0;
}
